package org.tacticalTroopers.jme.common.serializer;

import java.io.IOException;
import java.nio.ByteBuffer;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.tacticalTroopers.jme.common.message.Element;
import org.tacticalTroopers.jme.common.message.Id;

import com.jme3.network.serializing.Serializer;

public class ElementSerializer extends Serializer {
	
	Log log = LogFactory.getLog(getClass());
	
	@Override
	public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException {
		Integer i ;
		i = data.getInt();
		//data.get(i);
		log.info("generaing Id:"+i);
		Element e = new Element();
		e.setId(new Id().setValue(i));
		return (T)e;
	}

	@Override
	public void writeObject(ByteBuffer buffer, Object object) throws IOException {
		Element e = (Element)object;
		log.info("serializing Id:"+e.getId().getValue());
		buffer.putInt(e.getId().getValue().intValue());
	}
}
